package Thread;

import org.apache.commons.io .FileUtils;
import sun.misc.FileURLMapper;

import java.io.File;
import java.io.IOException;
import java.net.URL;

//联系Thread实现多线程下载图片
public class text02 implements   Runnable {
    public String url;
    public String name;

    public text02(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {

        WebDown xiazai = new WebDown();
        xiazai.down(url,name);
        System.out.println("下载完成");
    }

    public static void main(String[] args) {
        text02 text02 = new text02("https://i2.hdslb.com/bfs/face/83bb511365da513c55aa3d1958524f3b7db40684.jpg@96w_96h_1c.webp","2.jpg");
//        text02 text03 = new text02("https://i2.hdslb.com/bfs/face/83bb511365da513c55aa3d1958524f3b7db40684.jpg@96w_96h_1c.webp,","2.jpg");
//        text02 text04 = new text02("https://i2.hdslb.com/bfs/face/83bb511365da513c55aa3d1958524f3b7db40684.jpg@96w_96h_1c.webp,","2.jpg");

         Thread thread=new Thread(text02);
         thread.start();
//        text03.start();
//        text04.start();
    }
}
class WebDown{
    //下载方法
    public void down(String url,String name ){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name ));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IO异常");
        }
    }
}